package CheckFile;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.channels.FileChannel;

import javax.swing.JOptionPane;

public class CheckFile {
	
	public static void CheckHanLPFile(){
		File targetFile = new File("./bin/HanLP.properties"); 
		File sourceFile = new File("./lib/HanLP.properties");
		if(! sourceFile.exists()){
			JOptionPane.showMessageDialog(null, "lib文件夹中的HanLP配置文件不存在");
			return;
		}
		if(! targetFile.exists()){
			nioTransferCopy(sourceFile, targetFile);
			OverWrite.OverWriteHanLPFile();
		}
	}
	
	 private static void nioTransferCopy(File source, File target) {  
	    FileChannel in = null;  
	    FileChannel out = null;  
	    FileInputStream inStream = null;  
	    FileOutputStream outStream = null;  
	    try {  
	        inStream = new FileInputStream(source);  
	        outStream = new FileOutputStream(target);  
	        in = inStream.getChannel();  
	        out = outStream.getChannel();  
	        in.transferTo(0, in.size(), out);  
	    } catch (IOException e) {  
	        e.printStackTrace();  
	    } finally {     	
	        try {
	        	inStream.close();
				in.close();
				outStream.close();
		        out.close(); 
			} catch (IOException e) {
				e.printStackTrace();
			}          
	    }  
	} 

}
